﻿Public Class fClavesPrimarias
    Dim daClavePri As lbGlobalcom.dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter
    Private Sub btnCargarClavesPrimarias_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCargarClavesPrimarias.Click
        Try
            If Me.DsGlobal.GLO_CLAVESPRIMARIAS.GetChanges IsNot Nothing Then
                GLO_CLAVESPRIMARIASBindingSource.EndEdit()
                If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Cambios pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    GLO_CLAVESPRIMARIASBindingNavigatorSaveItem.PerformClick()
                End If
            End If
            daClavePri.Fill(DsGlobal.GLO_CLAVESPRIMARIAS)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub GLO_CLAVESPRIMARIASBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GLO_CLAVESPRIMARIASBindingNavigatorSaveItem.Click
        Try
            'If Me.DsGlobal.GLO_CLAVESPRIMARIAS.GetChanges() IsNot Nothing Then
            '    If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Cambios pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
            '        GLO_CLAVESPRIMARIASBindingNavigatorSaveItem.PerformClick()
            '    End If
            'End If
            Validate()
            GLO_CLAVESPRIMARIASBindingSource.EndEdit()
            daClavePri.Update(DsGlobal.GLO_CLAVESPRIMARIAS)
            MessageBox.Show("Se salvarón registros con exito", "Salva Registros", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub fClavesPrimarias_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            If Me.DsGlobal.GLO_CLAVESPRIMARIAS.GetChanges IsNot Nothing Then
                GLO_CLAVESPRIMARIASBindingSource.EndEdit()
                If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Cambios pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    GLO_CLAVESPRIMARIASBindingNavigatorSaveItem.PerformClick()
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub fClavesPrimarias_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        daClavePri = New lbGlobalcom.dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter
    End Sub

    Private Sub GLO_CLAVESPRIMARIASDataGridView_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles GLO_CLAVESPRIMARIASDataGridView.DataError
        MessageBox.Show(e.Exception.Message)
    End Sub

    Private Sub GLO_CLAVESPRIMARIASDataGridView_UserDeletedRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles GLO_CLAVESPRIMARIASDataGridView.UserDeletedRow
        Try
            daClavePri.Update(DsGlobal.GLO_CLAVESPRIMARIAS)
            MessageBox.Show("Registro borrado con exito", "Elimina regsitro", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub GLO_CLAVESPRIMARIASDataGridView_UserDeletingRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowCancelEventArgs) Handles GLO_CLAVESPRIMARIASDataGridView.UserDeletingRow
        If MessageBox.Show("Desea borrar el registro", "Elimina registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
            e.Cancel = True
        End If
    End Sub

    Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        If MessageBox.Show("Desea borrar el registro", "Elimina registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
            GLO_CLAVESPRIMARIASBindingSource.Remove(GLO_CLAVESPRIMARIASBindingSource.Current)
            GLO_CLAVESPRIMARIASBindingNavigatorSaveItem.PerformClick()
        End If
    End Sub
End Class